package ltd.rycloud.tms.service;

import java.util.List;

import ltd.rycloud.tms.dao.UserDao;
import ltd.rycloud.tms.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserService {
	@Autowired
	UserDao userDao;
	//注册
	public User save(User user){
		return userDao.save(user);
	}
	//登录
	public User login(String username,String password) {
		return userDao.findByUsernameAndPassword(username,password);
	}
	//修改(需要传Id)
	public User update(User user) {
		return userDao.save(user);
	}
	//删除
	public void delete(int id) {
		userDao.deleteById(id);
	}
	//查询
	public List<User> findAll(){
		return userDao.findAll();
	}
	//通过Id查询
	public User getUser(int id) {
		return userDao.findById(id).get();
	}
	public  User edit(User user)
	{
		//user.setLastlogindate(new Date());
		return  userDao.save(user);
	}
}
